package com.zxyankh.generator.math.practice;

import java.util.List;

import com.zxyankh.generator.math.practice.dto.Options;
import com.zxyankh.generator.math.practice.dto.Problem;
import com.zxyankh.generator.math.practice.impl.TxtProblemOutput;

public class Starter {

	public static void main(String[] args) {
		Options options = parseArgs(args);
		System.out.println(options.getOptions());

		Generator generator = new Generator();
		List<Problem> problemList = generator.generateProblems(options);
		problemList.forEach(System.out::println);

		ProblemOutput problemOutput = new TxtProblemOutput();
		problemOutput.output(problemList);
	}

	private static Options parseArgs(String[] args) {
		Options options = new Options();
		for (String arg : args) {
			if (arg.startsWith("-sumCapped=")) {
				options.setSumCapped(Integer.parseInt(arg.substring(11)));
			} else if (arg.startsWith("-hasNegative=")) {
				options.setNegativeNumber(arg.charAt(13) == '1');
			} else if (arg.startsWith("-number=")) {
				options.setProblemNumber(Integer.parseInt(arg.substring(8)));
			} else if (arg.startsWith("-hasSubtract=")) {
				options.setSubtraction(arg.charAt(13) == '1');
			}
		}
		return options;
	}

}
